Skip to content

Introduce wc_stripe_force_save_payment_method filter #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Mayisha
Copy link
Contributor

@Mayisha Mayisha commented Apr 18, 2025

Fixes STRIPE-229
Fixes #3502

Changes proposed in this Pull Request:

  • Introduced a new filter 'wc_stripe_force_save_payment_method' which is equivalent to the 'wc_stripe_force_save_source' filter available for the legacy checkout.
  • Instead of applying the existing 'wc_stripe_force_save_source' filter I have deprecated it and introduced the new filter to ensure correct terminology. In legacy checkout which was implemented based on the Sources API, the previous filter make sense. But in the new checkout experience which is based on the payment methods and Sources being a deprecated API, introducing the 'wc_stripe_force_save_payment_method' filter is more aligned with the feature.

Testing instructions

  • In your Stripe settings page, enable Enable payments via saved cards.
  • As a logged in shopper, purchase a product with card. Make sure the Save payment information to my account for future purchases checkbox is not selected.
  • Go to My Account > Payment methods page as the shopper and confirm that the card is not saved.
  • Add the following filter using code snippet.
add_filter( 'wc_stripe_force_save_payment_method', '__return_true', 10, 2 );
  • As a shopper purchase a product with card. Make sure the Save payment information to my account for future purchases checkbox is not selected.
  • Go to My Account > Payment methods page as the shopper and confirm that the card is saved this time.
  • Remove the previous filter and add the following filter using code snippet to check backward compatibility.
add_filter( 'wc_stripe_force_save_source', '__return_true', 10, 2 );
  • As a shopper purchase a product with card. Make sure the Save payment information to my account for future purchases checkbox is not selected.
  • Go to My Account > Payment methods page as the shopper and confirm that the card is saved.
  • Regression test
    • Complete checkout with a non card method with and without the filter. Ensure that there are no errors.
    • Confirm that checkout with Save payment information to my account for future purchases works as before.

Note
I will add a changelog under 9.6.0.

@Mayisha Mayisha marked this pull request as draft April 18, 2025 16:00
Copy link

github-actions bot commented May 7, 2025

📈 PHP Unit Code Coverage Report

Package Line Rate Health
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php 49%
Summary 44% (7254 / 16308)

@Mayisha Mayisha marked this pull request as ready for review May 7, 2025 13:38
@Mayisha Mayisha requested review from a team and daledupreez and removed request for a team May 7, 2025 13:38
Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working for me, but I have objections to the UX, specifically this sequence (emphasis mine):

  • As a shopper purchase a product with card. Make sure the Save payment information to my account for future purchases checkbox is not selected.
  • Go to My Account > Payment methods page as the shopper and confirm that the card is saved this time.

While saving their payment method is something a merchant may really want to do, giving the user no indication that this will happen doesn't feel right. Can we instead include the return value of the filter to the UI and ensure that the checkbox is checked and disabled when the value is true?

I see we already have logic to hide the checkbox when we want to force saving the payment method (which we're not using in this PR), but that also feels problematic given that there's no indication that the payment method will be saved.

/**
* Displays the save to account checkbox.
*
* @since 4.1.0
* @version 5.6.0
*/
public function save_payment_method_checkbox( $force_checked = false ) {
$id = 'wc-' . $this->id . '-new-payment-method';
?>
<fieldset <?php echo $force_checked ? 'style="display:none;"' : ''; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?>>
<p class="form-row woocommerce-SavedPaymentMethods-saveNew">
<input id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $id ); ?>" type="checkbox" value="true" style="width:auto;" <?php echo $force_checked ? 'checked' : ''; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?> />
<label for="<?php echo esc_attr( $id ); ?>" style="display:inline;">
<?php echo esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) ); ?>
</label>
</p>
</fieldset>
<?php
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UPE: Missing equivalent to the wc_stripe_force_save_source hook
2 participants